1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2016 Couchbase, Inc.
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  */
17 
18 #include <cbsasl/error.h>
19 #include <stdexcept>
20 
to_string(cb::sasl::Error error)21 std::string to_string(cb::sasl::Error error) {
22     using Error = cb::sasl::Error;
23     switch (error) {
24     case Error::OK:
25         return "Success";
26     case Error::CONTINUE:
27         return "Continue";
28     case Error::FAIL:
29         return "Fail";
30     case Error::BAD_PARAM:
31         return "Invalid parameters";
32     case Error::NO_MEM:
33         return "No memory";
34     case Error::NO_MECH:
35         return "No such mechanism";
36     case Error::NO_USER:
37         return "No such user";
38     case Error::PASSWORD_ERROR:
39         return "Invalid password";
40     case Error::NO_RBAC_PROFILE:
41         return "User not defined in Couchbase";
42     case Error::AUTH_PROVIDER_DIED:
43         return "Auth provider died";
44     }
45 
46     throw std::invalid_argument(
47             "to_string(cb::sasl::Error error): Unknown error: " +
48             std::to_string(int(error)));
49 }
50