Skip to content

Commit

Permalink
chore: remove response attribute from appwriteexception
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiragAgg5k committed Jan 28, 2025
1 parent 612b2e0 commit 6e45683
Show file tree
Hide file tree
Showing 21 changed files with 28 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,7 @@ class Client @JvmOverloads constructor(
{{ spec.title | caseUcfirst }}Exception(
map["message"] as? String ?: "",
(map["code"] as Number).toInt(),
map["type"] as? String ?: "",
body
map["type"] as? String ?: ""
)
} else {
{{ spec.title | caseUcfirst }}Exception(body, response.code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ import java.lang.Exception
class {{spec.title | caseUcfirst}}Exception(
override val message: String? = null,
val code: Int? = null,
val type: String? = null,
val response: String? = null
val type: String? = null
) : Exception(message)
4 changes: 2 additions & 2 deletions templates/cli/lib/client.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Client {
try {
json = JSON.parse(text);
} catch (error) {
throw new {{spec.title | caseUcfirst}}Exception(text, response.status, "", text);
throw new {{spec.title | caseUcfirst}}Exception(text, response.status, "");
}

if (path !== '/account' && json.code === 401 && json.type === 'user_more_factors_required') {
Expand All @@ -158,7 +158,7 @@ class Client {
globalConfig.setCurrentSession('');
globalConfig.removeSession(current);
}
throw new {{spec.title | caseUcfirst}}Exception(json.message, json.code, json.type, json);
throw new {{spec.title | caseUcfirst}}Exception(json.message, json.code, json.type);
}

if (responseType === "arraybuffer") {
Expand Down
3 changes: 1 addition & 2 deletions templates/cli/lib/exception.js.twig
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class {{ spec.title| caseUcfirst }}Exception extends Error {
constructor(message, code, response) {
constructor(message, code) {
super(message);
this.code = code;
this.response = response;
}
}

Expand Down
1 change: 0 additions & 1 deletion templates/dart/lib/src/client_mixin.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class ClientMixin {
response['message'],
response['code'],
response['type'],
response,
);
} else {
throw {{spec.title | caseUcfirst}}Exception(res.body);
Expand Down
3 changes: 1 addition & 2 deletions templates/dart/lib/src/exception.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ class {{spec.title | caseUcfirst}}Exception implements Exception {
/// for more information.
final String? type;
final int? code;
final dynamic response;

/// Initializes an {{spec.title | caseUcfirst}} Exception.
{{spec.title | caseUcfirst}}Exception([this.message = "", this.code, this.type, this.response]);
{{spec.title | caseUcfirst}}Exception([this.message = "", this.code, this.type]);

/// Returns the error type, message, and code.
@override
Expand Down
4 changes: 2 additions & 2 deletions templates/deno/src/client.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ export class Client {
try {
json = JSON.parse(text);
} catch (error) {
throw new {{spec.title | caseUcfirst}}Exception(text, response.status, "", text);
throw new {{spec.title | caseUcfirst}}Exception(text, response.status, "");
}
throw new {{spec.title | caseUcfirst}}Exception(json.message, json.code, json.type, json);
throw new {{spec.title | caseUcfirst}}Exception(json.message, json.code, json.type);
}

if (responseType === "arraybuffer") {
Expand Down
6 changes: 2 additions & 4 deletions templates/deno/src/exception.ts.twig
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
export class {{ spec.title | caseUcfirst}}Exception {
message: string;
code: number;
response: any;
type: string;

constructor(message: string, code: number = 0, type: string = "", response: any = "") {
constructor(message: string, code: number = 0, type: string = "") {
this.message = message;
this.code = code;
this.type = type;
this.response = response;
}

public toString(): string {
return `${this.message} - ${this.code} - ${this.type} - ${JSON.stringify(this.response)}`;
return `${this.message} - ${this.code} - ${this.type}`;
}
}
5 changes: 1 addition & 4 deletions templates/dotnet/Package/Exception.cs.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ namespace {{spec.title | caseUcfirst}}
{
public int? Code { get; set; }
public string? Type { get; set; } = null;
public string? Response { get; set; } = null;

public {{spec.title | caseUcfirst}}Exception(
string? message = null,
int? code = null,
string? type = null,
string? response = null) : base(message)
string? type = null) : base(message)
{
this.Code = code;
this.Type = type;
this.Response = response;
}
public {{spec.title | caseUcfirst}}Exception(string message, Exception inner)
: base(message, inner)
Expand Down
1 change: 0 additions & 1 deletion templates/flutter/lib/src/client_mixin.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class ClientMixin {
response['message'],
response['code'],
response['type'],
response,
);
} else {
throw {{spec.title | caseUcfirst}}Exception(res.body);
Expand Down
6 changes: 2 additions & 4 deletions templates/kotlin/src/main/kotlin/io/appwrite/Client.kt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,7 @@ class Client @JvmOverloads constructor(
{{ spec.title | caseUcfirst }}Exception(
map["message"] as? String ?: "",
(map["code"] as Number).toInt(),
map["type"] as? String ?: "",
body
map["type"] as? String ?: ""
)
} else {
{{ spec.title | caseUcfirst }}Exception(body, response.code)
Expand Down Expand Up @@ -533,8 +532,7 @@ class Client @JvmOverloads constructor(
{{ spec.title | caseUcfirst }}Exception(
map["message"] as? String ?: "",
(map["code"] as Number).toInt(),
map["type"] as? String ?: "",
body
map["type"] as? String ?: ""
)
} else {
{{ spec.title | caseUcfirst }}Exception(body, response.code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ import java.lang.Exception
class {{spec.title | caseUcfirst}}Exception(
override val message: String? = null,
val code: Int? = null,
val type: String? = null,
val response: String? = null
val type: String? = null
) : Exception(message)
4 changes: 1 addition & 3 deletions templates/node/src/client.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ type Headers = {

class {{spec.title | caseUcfirst}}Exception extends Error {
code: number;
response: string;
type: string;
constructor(message: string, code: number = 0, type: string = '', response: string = '') {
super(message);
this.name = '{{spec.title | caseUcfirst}}Exception';
this.message = message;
this.code = code;
this.type = type;
this.response = response;
}
}

Expand Down Expand Up @@ -282,7 +280,7 @@ class Client {
}

if (400 <= response.status) {
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type, data);
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type);
}

return data;
Expand Down
4 changes: 2 additions & 2 deletions templates/php/src/Client.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,14 @@ class Client
}
if (curl_errno($ch)) {
throw new {{spec.title | caseUcfirst}}Exception(curl_error($ch), $responseStatus, $responseBody['type'] ?? '', $responseBody);
throw new {{spec.title | caseUcfirst}}Exception(curl_error($ch), $responseStatus, $responseBody['type'] ?? '');
}
curl_close($ch);
if($responseStatus >= 400) {
if(is_array($responseBody)) {
throw new {{spec.title | caseUcfirst}}Exception($responseBody['message'], $responseStatus, $responseBody['type'] ?? '', json_encode($responseBody));
throw new {{spec.title | caseUcfirst}}Exception($responseBody['message'], $responseStatus, $responseBody['type'] ?? '');
} else {
throw new {{spec.title | caseUcfirst}}Exception($responseBody, $responseStatus);
}
Expand Down
18 changes: 1 addition & 17 deletions templates/php/src/Exception.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ use Exception;
class {{spec.title | caseUcfirst}}Exception extends Exception {
/**
* @var mixed
*/
private ?string $response;
/**
* @var string
*/
Expand All @@ -20,16 +15,13 @@ class {{spec.title | caseUcfirst}}Exception extends Exception {
* @param ?string $message
* @param int $code
* @param string $type
* @param ?string $response
*/
public function __construct(
?string $message = null,
int $code = 0,
string $type = '',
?string $response = null
string $type = ''
) {
parent::__construct($message, $code);
$this->response = $response;
$this->type = $type;
}
Expand All @@ -40,12 +32,4 @@ class {{spec.title | caseUcfirst}}Exception extends Exception {
{
return $this->type;
}
/**
* @return ?string
*/
final public function getResponse(): ?string
{
return $this->response;
}
}
2 changes: 1 addition & 1 deletion templates/python/package/client.py.twig
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Client:
if response != None:
content_type = response.headers['Content-Type']
if content_type.startswith('application/json'):
raise {{spec.title | caseUcfirst}}Exception(response.json()['message'], response.status_code, response.json().get('type'), response.json())
raise {{spec.title | caseUcfirst}}Exception(response.json()['message'], response.status_code, response.json().get('type'))
else:
raise {{spec.title | caseUcfirst}}Exception(response.text, response.status_code)
else:
Expand Down
3 changes: 1 addition & 2 deletions templates/python/package/exception.py.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class {{spec.title | caseUcfirst}}Exception(Exception):
def __init__(self, message, code = 0, type = None, response = None):
def __init__(self, message, code = 0, type = None):
self.message = message
self.code = code
self.type = type
self.response = response
super().__init__(self.message)
6 changes: 2 additions & 4 deletions templates/react-native/src/client.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,13 @@ export type UploadProgress = {

class {{spec.title | caseUcfirst}}Exception extends Error {
code: number;
response: string;
type: string;
constructor(message: string, code: number = 0, type: string = '', response: string = '') {
constructor(message: string, code: number = 0, type: string = '') {
super(message);
this.name = '{{spec.title | caseUcfirst}}Exception';
this.message = message;
this.code = code;
this.type = type;
this.response = response;
}
}

Expand Down Expand Up @@ -430,7 +428,7 @@ class Client {
}

if (400 <= response.status) {
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type, data);
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type);
}

const cookieFallback = response.headers.get('X-Fallback-Cookies');
Expand Down
6 changes: 3 additions & 3 deletions templates/ruby/lib/container/client.rb.twig
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ module {{ spec.title | caseUcfirst }}
begin
result = JSON.parse(response.body)
rescue JSON::ParserError => e
raise {{spec.title | caseUcfirst}}::Exception.new(response.body, response.code, nil, response)
raise {{spec.title | caseUcfirst}}::Exception.new(response.body, response.code)
end

if response.code.to_i >= 400
raise {{spec.title | caseUcfirst}}::Exception.new(result['message'], result['status'], result['type'], result)
raise {{spec.title | caseUcfirst}}::Exception.new(result['message'], result['status'], result['type'])
end

unless response_type.respond_to?("from")
Expand All @@ -263,7 +263,7 @@ module {{ spec.title | caseUcfirst }}
end

if response.code.to_i >= 400
raise {{spec.title | caseUcfirst}}::Exception.new(response.body, response.code, response)
raise {{spec.title | caseUcfirst}}::Exception.new(response.body, response.code)
end

if response.respond_to?("body_permitted?")
Expand Down
4 changes: 1 addition & 3 deletions templates/ruby/lib/container/exception.rb.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ module {{spec.title | caseUcfirst}}
class Exception < StandardError
attr_reader :code
attr_reader :response
attr_reader :type

def initialize(message, code = 0, type = nil, response = nil)
def initialize(message, code = 0, type = nil)
super(message)
@code = code
@type = type
@response = response
end
end
end
10 changes: 2 additions & 8 deletions templates/web/src/client.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,6 @@ class {{spec.title | caseUcfirst}}Exception extends Error {
*/
code: number;

/**
* The response string associated with the exception.
*/
response: string;

/**
* Error type.
* See [Error Types]({{sdk.url}}/docs/response-codes#errorTypes) for more information.
Expand All @@ -281,13 +276,12 @@ class {{spec.title | caseUcfirst}}Exception extends Error {
* @param {string} type - The error type. Default is an empty string.
* @param {string} response - The response string. Default is an empty string.
*/
constructor(message: string, code: number = 0, type: string = '', response: string = '') {
constructor(message: string, code: number = 0, type: string = '') {
super(message);
this.name = '{{spec.title | caseUcfirst}}Exception';
this.message = message;
this.code = code;
this.type = type;
this.response = response;
}
}

Expand Down Expand Up @@ -688,7 +682,7 @@ class Client {
}

if (400 <= response.status) {
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type, data);
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type);
}

const cookieFallback = response.headers.get('X-Fallback-Cookies');
Expand Down

0 comments on commit 6e45683

Please sign in to comment.